package com.codedancer.campus.manager.api.chatRoom;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.chatRoom.ro.ChatRoomPageSearchRo;
import com.codedancer.campus.manager.service.IChatRoomService;
import com.codedancer.campus.manager.service.bo.chatRoom.ChatRoomPageSearchBo;
import com.codedancer.campus.manager.service.vo.chatRoom.ChatRoomPageVo;
import com.codedancer.campus.manager.service.vo.chatRoom.ChatRoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/chat-room")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "聊天室Api", description = "聊天室Api", tags = "聊天室Api")
public class ChatRoomApi extends BaseApi {

    @Autowired
    private IChatRoomService chatRoomService;

    @GetMapping("/page")
    @ApiOperation("分页查询聊天室")
    @InterfacePermission(encodes = {"superAdmin"})
    public ApiResponse<IPage<ChatRoomPageVo>> page(@ApiParam(value = "聊天室分页搜索Ro", required = false)
        ChatRoomPageSearchRo chatRoomPageSearchRo) {
        ChatRoomPageSearchBo chatRoomPageSearchBo = BeanUtil
            .copyProperties(chatRoomPageSearchRo, ChatRoomPageSearchBo.class);
        return success(chatRoomService.page(chatRoomPageSearchBo));
    }

    @GetMapping("/detail/{uuid}")
    @ApiOperation("详情")
    @InterfacePermission(encodes = {"superAdmin"})
    public ApiResponse<ChatRoomVo> detail(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "聊天室uuid", required = true) String uuid) {
        return success(chatRoomService.detail(uuid));
    }
}
